<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>对象解构</title>
  <script type="text/javascript">
    let person = {
      name: "tom",
      age: 18
    }
    // 传统解构对象
    console.log("name = ", person.name, "  age = ", person.age);
    // ES6解构对象
    // 解释: 将person对象的属性赋值给{name, age}
    // {name, age} 必须与person属性名相同,顺序可不同
    let {name, age} = person;
    console.log("name: ", name, "  age: ", age);
    // let {name, age} = {
    //   name: "jack",
    //   age: 20
    // }
    // console.log("name: ", name, "  age: ", age);与上述写法相同
    // 使用方法解构对象原理一致
    function func({name, age}) {
      console.log("func-name: ", name, "  func-age: ", age);
    }
    func(person);
  </script>
</head>
<body>
</body>
</html>
